package com.fc.employee.controller;


import com.fc.commonutils.MD5;
import com.fc.commonutils.R;
import com.fc.employee.entity.Employee;
import com.fc.employee.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zwy
 * @since 2022-09-05
 */
@RestController
@RequestMapping("/employee/employee")
@CrossOrigin
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /**
     * 添加管理员
     */
    @PostMapping("/add")
    public R register(@RequestBody Employee employee) {
        employee.setPassword(MD5.encrypt(employee.getPassword()));
        employeeService.save(employee);
        return R.ok();
    }

    /**
     * 登录
     */
    @PostMapping("/login")
    public R login(String phone, String password) {
        //返回token
        String token = employeeService.login(phone, password);
        return R.ok().data("token", token);
    }
}

